You've built the class! Now, just write the main script to read the $N$ commands and call your methods.
Guidance for Step 5
- This part is about string parsing and calling the object methods you just wrote.
-
Create an instance of your
PriorityQueue. -
Read
n, then loopntimes. -
Remember to convert
kto anintfor thepushoperation. -
The blanks are for calling the correct method on your
pqobject.
# (Make sure your class definition is above this)
# Create a new Priority Queue
pq = PriorityQueue()
# Read the number of operations
n = int(input().strip())
# Process each operation
for _ in range(n):
line = input().strip().split()
cmd = line[0]
if cmd == "push":
k = int(line[1])
________ # Call the push method
elif cmd == "peek":
print(________) # Call the peek method
elif cmd == "pop":
print(________) # Call the pop method
Copied!